package com.zbest.zpay.acctrans.common.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;

public class CryptUtils {

    public String cryptMd5(String paramString1, String paramString2) {
        byte[] arrayOfByte3;
        byte[] arrayOfByte4;
        byte[] arrayOfByte1 = new byte[64];
        byte[] arrayOfByte2 = new byte[64];
        try {
            arrayOfByte3 = paramString2.getBytes("UTF-8");
            arrayOfByte4 = paramString1.getBytes("UTF-8");
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            arrayOfByte3 = paramString2.getBytes();
            arrayOfByte4 = paramString1.getBytes();
        }
        Arrays.fill(arrayOfByte1, arrayOfByte3.length, 64, (byte) 54);
        Arrays.fill(arrayOfByte2, arrayOfByte3.length, 64, (byte) 92);

        for (int i = 0; i < arrayOfByte3.length; ++i) {
            arrayOfByte1[i] = (byte) (arrayOfByte3[i] ^ 0x36);
            arrayOfByte2[i] = (byte) (arrayOfByte3[i] ^ 0x5C);
        }
        MessageDigest localMessageDigest = null;
        try {
            localMessageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
            return null;
        }
        localMessageDigest.update(arrayOfByte1);
        localMessageDigest.update(arrayOfByte4);
        byte[] arrayOfByte5 = localMessageDigest.digest();
        localMessageDigest.reset();
        localMessageDigest.update(arrayOfByte2);
        localMessageDigest.update(arrayOfByte5, 0, 16);
        arrayOfByte5 = localMessageDigest.digest();
        return toHex(arrayOfByte5);
    }

    public String cryptMd5(String paramString) {
        byte[] arrayOfByte1;
        try {
            arrayOfByte1 = paramString.getBytes("UTF-8");
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
            arrayOfByte1 = paramString.getBytes();
        }
        MessageDigest localMessageDigest = null;
        try {
            localMessageDigest = MessageDigest.getInstance("MD5");
        } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
            return null;
        }
        localMessageDigest.update(arrayOfByte1);
        byte[] arrayOfByte2 = localMessageDigest.digest();
        return toHex(arrayOfByte2);
    }

    public static String toHex(byte[] paramArrayOfByte) {
        if (paramArrayOfByte == null)
            return null;

        StringBuffer localStringBuffer = new StringBuffer(
                paramArrayOfByte.length * 2);
        for (int i = 0; i < paramArrayOfByte.length; ++i) {
            int j = paramArrayOfByte[i] & 0xFF;
            if (j < 16)
                localStringBuffer.append("0");
            localStringBuffer.append(Integer.toString(j, 16));
        }

        return localStringBuffer.toString();
    }

//	public static void main(String[] paramArrayOfString) {
//
//		// CryptUtil localCryptUtilImpl = new CryptUtil();
//		// String str1 = "123456781234567812345678";
//		// String str2 = "123456";
//		// String aa=localCryptUtilImpl.cryptMd5(str1, str2);
//		// System.out.println(aa);
//		//
//		// String bb=localCryptUtilImpl.cryptMd5(str1+str2);
//		// System.out.println(bb);
//		Money m = new Money(0, 20,
//				Currency.getInstance(Money.DEFAULT_CURRENCY_CODE));
//		System.out.println(m.getCent());
//		String aa = CreatBalanceTag
//				.execute("10020150106000000000001", "100", m);
//		System.out.println(aa);
//	}

}
